package br.great.classes;

import java.util.Vector;
import br.great.beans.TrackPoint;

/**
* PhotoMap
* Copyright (c) 2007-2008 STEAMER - LIG, All rights reserved.
*/

/**
 * @author Developpement of PhotoMap
 */
public class CenterDistance_TrackpointList {
    double minLat;
    double minLng;
    double maxLat;
    double maxLng;
    double centerLat;
    double centerLng;
    double disLat;
    double disLng;
 
    public String[] getCenterAndDistance(Vector<TrackPoint> tps){
        String[] cen_dis = new String[2];
        if(tps!=null||tps.size()!=0){
        TexteRange tr = new TexteRange();
        
        TrackPoint tp0 = tps.get(0);
//System.out.println("getCenterAndDistance "+tp0.getTrackPointCoordinateAsString());
        String[] stb0 = tr.getInfoWithEspace(tp0.getTrackPointCoordinateAsString());
        minLat=maxLat=Double.parseDouble(stb0[0]);
        minLng=maxLng=Double.parseDouble(stb0[1]);
        for (int i=1; i<tps.size(); i++){
            TrackPoint tp = tps.elementAt(i);
            String[] stb = tr.getInfoWithEspace(tp.getTrackPointCoordinateAsString());
            Double tpLat = Double.parseDouble(stb[0]);
            Double tpLng = Double.parseDouble(stb[1]);
            
            if (tpLat<minLat){
                minLat = tpLat;
            }else if (tpLat>maxLat){
                maxLat = tpLat;
            }
            if (tpLng<minLng){
                minLng = tpLng;
            }else if (tpLng>maxLng){
                maxLng = tpLng;
            }
        }
        disLat = (maxLat-minLat)/2;
        disLng = (maxLng-minLng)/2;
        centerLat = disLat + minLat;
        centerLng = disLng + minLng;
        
        cen_dis[0] = "POINT("+centerLat+" "+centerLng+")";
        cen_dis[1] = "POINT("+disLat+" "+disLng+")";
        }
        return cen_dis;
    }
    
//    public static void main(String[] args){
//        CenterDistance_TrackpointList cdtp = new CenterDistance_TrackpointList();
//        Vector<TrackPoint> vtp = new Vector<TrackPoint>();
//
//            for (int j=0; j<1; j++){
//                TrackPoint tp = new TrackPoint();
//                tp.setLatitude(44.5);
//                tp.setLongitude(6);
//                TrackPoint tp2 = new TrackPoint();
//                tp2.setLatitude(456);
//                tp2.setLongitude(5);
//                vtp.add(tp);
//                vtp.add(tp2);
//            }
//
//        System.out.println(cdtp.getCenterAndDistance(vtp)[0]);
//        System.out.println(cdtp.getCenterAndDistance(vtp)[1]);
//    }
}
